package text

import (
	"bytes"
	"golang.org/x/text/encoding/simplifiedchinese"
	"golang.org/x/text/transform"
	"io/ioutil"
)

func Utf8ToGBK(bs []byte) ([]byte, error) {
	reader := transform.NewReader(bytes.NewReader(bs), simplifiedchinese.GBK.NewEncoder())
	all, err := ioutil.ReadAll(reader)
	if err != nil {
		return nil, err
	}
	return all, nil
}

func GBKToUtf8(bs []byte) ([]byte, error) {
	reader := transform.NewReader(bytes.NewReader(bs), simplifiedchinese.GBK.NewDecoder())
	all, err := ioutil.ReadAll(reader)
	if err != nil {
		return nil, err
	}
	return all, nil
}
